package com.zx._12_算法.剑指offer._2022;

/**
 * https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
 */
public class 左旋转字符串 {

    public String reverseLeftWords1(String s, int n) {
        char[] res = new char[s.length()];
        for (int i = 0; i < s.length(); i++) {
            int newIdx = i - n;
            if (newIdx < 0) {
                newIdx = newIdx + s.length();
            }
            res[newIdx] = s.charAt(i);
        }
        return new String(res);
    }

    public String reverseLeftWords(String s, int n) {
        return s.substring(n, s.length()) + s.substring(0, n);
    }
}
